package ren.kane.phoenix.util.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

/**
 * @author renrk(1275) on 2019-08-12 4:37 PM
 **/
public class PrintStreamTest {

    private static void testPrintStreamConstructor1() {
        // 将字母“abcde”写入到文件“file.txt”中
        final byte[] arr = {0x61, 0x62, 0x63, 0x64, 0x65};
        try {
            PrintStream printStream = new PrintStream(new FileOutputStream(new File("dir", "file.txt")));
            printStream.write(arr);
            printStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void testPrintStreamConstructor2() {
        final byte[] arr = {0x61, 0x62, 0x63, 0x64, 0x65};
        try {
            PrintStream printStream = new PrintStream(new File("dir", "other.txt"));
            printStream.println("hello printStream");
            printStream.write(0x41);
            printStream.print(0x41);
            printStream.append('B');
            String str = "CDE";
            printStream.printf("%s is %d\n", str, 5);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        testPrintStreamConstructor1();
        testPrintStreamConstructor2();
    }
}
